#git clone git://sourceware.org/git/binutils-gdb.git CVE-2017-8392
rm -rf ./CVE-2019-10873
#cp -r /binutils ./CVE-2019-10872
git clone https://gitlab.freedesktop.org/poppler/poppler.git CVE-2019-10873
cd CVE-2019-10873; git checkout eec84fe2
mkdir obj-aflgo; mkdir obj-aflgo/temp
export SUBJECT=$PWD; export TMP_DIR=$PWD/obj-aflgo/temp
export CC=$AFLGO/afl-clang-fast; export CXX=$AFLGO/afl-clang-fast++
export LDFLAGS=-lpthread
export ADDITIONAL="-targets=$TMP_DIR/BBtargets.txt -outdir=$TMP_DIR -flto -fuse-ld=gold -Wl,-plugin-opt=save-temps -DFORTIFY_SOURCE=2 -fstack-protector-all -fno-omit-frame-pointer -g -Wno-error"
echo $'SplashXPathScanner.cc:458' > $TMP_DIR/BBtargets.txt
#echo $'Splash.cc:5872\nGfx.cc:4764\nGfx.cc:4182\nGfx.cc:4182\nGfx.cc:753\nGfx.cc:715\nGfx.cc:4841\nPage.cc:548\nPDFDoc.cc:665\n' > $TMP_DIR/real.txt
echo $'SplashXPathScanner.cc:458' > $TMP_DIR/real.txt
cd obj-aflgo; CFLAGS="$ADDITIONAL" LDFLAGS="-ldl -lutil" CXXFLAGS="$ADDITIONAL" 
#../configure --disable-shared --disable-gdb --disable-libdecnumber --disable-readline --disable-sim --disable-ld
cmake .. -DCMAKE_CXX_COMPILER=$AFLGO/afl-clang-fast++ -DCMAKE_CXX_FLAGS="$ADDITIONAL"
make clean; make
cat $TMP_DIR/BBnames.txt | rev | cut -d: -f2- | rev | sort | uniq > $TMP_DIR/BBnames2.txt && mv $TMP_DIR/BBnames2.txt $TMP_DIR/BBnames.txt
cat $TMP_DIR/BBcalls.txt | sort | uniq > $TMP_DIR/BBcalls2.txt && mv $TMP_DIR/BBcalls2.txt $TMP_DIR/BBcalls.txt
cd utils; $AFLGO/scripts/genDistance.sh $SUBJECT $TMP_DIR libpoppler.so.86.0.0
cd ../../; mkdir obj-dist; cd obj-dist; # work around because cannot run make distclean
CFLAGS="-DFORTIFY_SOURCE=2 -fstack-protector-all -fno-omit-frame-pointer -g -Wno-error -distance=$TMP_DIR/distance.cfg.txt" LDFLAGS="-ldl -lutil" CXXFLAGS="-DCMAKE_CXX_COMPILER=$AFLGO/afl-clang-fast++ -DFORTIFY_SOURCE=2 -fstack-protector-all -fno-omit-frame-pointer -g -Wno-error $ADDITIONAL" 
export ADDITIONAL="-distance=$TMP_DIR/distance.cfg.txt -DFORTIFY_SOURCE=2 -fstack-protector-all -fno-omit-frame-pointer -g -Wno-error" 
LDFLAGS="-ldl -lutil"
#../configure --disable-shared --disable-gdb --disable-libdecnumber --disable-readline --disable-sim --disable-ld
cmake .. -DCMAKE_CXX_COMPILER=$AFLGO/afl-clang-fast++ -DCMAKE_CXX_FLAGS="$ADDITIONAL"
make clean; make
mkdir in; 
#echo "" > in/in
cp /selectfuzz/scripts/fuzz/10873.pdf in/in 
$AFLGO/afl-fuzz -m none -c 45m -i in -o out -d -- ./utils/pdftoppm -cropbox -jpeg -freetype yes @@ tmp
